define(function(){
	dmw.goScroll = function (opts){
		var dayLen = 0,
			self = dmw.goScroll;
		self.scrollTopArr = [];
		self.DEFAULT = {
			tabsDiv : $("#tabs").children('div'),
			contentDiv : $("#content").children("div"),
			activeClass : 'active',
			speed : 600,
			diff : 0
		}
		self.DEFAULT =  $.extend(self,self.DEFAULT,opts);
		self.auto = function  (){
			var intiActive = null;
			dayLen = self.DEFAULT.tabsDiv.eq(0).attr("id").length;
			self.getScrollTop();
			$(window).scroll(function(){
				var st = $(window).scrollTop();
				$(self.scrollTopArr).each(function(k,ele){
					if(self.scrollTopArr[k]<st && st<self.scrollTopArr[k+1]){
						intiActive = self.DEFAULT.contentDiv.eq(k).attr("id").slice(-dayLen);
						$("#"+intiActive).addClass(self.DEFAULT.activeClass).siblings().removeClass(self.DEFAULT.activeClass);
						return false;
					}else if(st > self.scrollTopArr[self.scrollTopArr.length-1]){
		            	self.DEFAULT.tabsDiv.last().addClass(self.DEFAULT.activeClass).siblings().removeClass(self.DEFAULT.activeClass);
		            	return false;
		            }
				});
			})
		}
		self.DEFAULT.tabsDiv.on('touchend',function(event) {
			event.preventDefault();
			var dayCentent = self.DEFAULT.contentDiv.eq(0).attr("id").slice(0,-dayLen);
			self.goAnchor("#"+dayCentent+$(this).attr("id"),self.DEFAULT.speed,self.DEFAULT.diff);
		});
		self.goAnchor = function (select,time,diff){
			if($(select).length<=0) return;
			var _top=$(select).offset().top;
			$("html,body").animate({scrollTop:_top+diff},time);
		};
		self.getScrollTop = function (){
			self.DEFAULT.contentDiv.each(function(v,k){
				self.scrollTopArr[v] = k.offsetTop+self.DEFAULT.diff*2;
			});
		}
		self.auto();
		return dmw.goScroll ;
	}
})